<template>
	<view class="page">
		<view class="name2">
			<text class="name2_1">{{info.sname}} {{info.dir}}</text>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">屏前温度:</text>
				</u-col>
				<!-- <u-col span="0.5">
					<text class="title">开</text>
				</u-col> -->
				<u-col span="4">
					<uni-number-box class="num" v-model="formData.temp1_1" ></uni-number-box>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<uni-number-box class="num" v-model="formData.temp1_2" ></uni-number-box>
				</u-col>
			</u-row>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">箱体温度:</text>
				</u-col>
				<!-- <u-col span="0.5">
					<text class="title">开</text>
				</u-col> -->
				<u-col span="4">
					<uni-number-box class="num" v-model="formData.temp2_1" ></uni-number-box>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<uni-number-box class="num" v-model="formData.temp2_2" ></uni-number-box>
				</u-col>
			</u-row>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">Arm时间:</text>
				</u-col>
				<u-col span="4">
					<view @click="click3(1)">
						<uni-easyinput type="text" v-model="formData.time1_1" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show1_1" v-model="formData.time1_1" mode="time" @confirm="confirm1(1)"
							@cancel="cancel1(1)"></u-datetime-picker>
					</view>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<view @click="click4(1)">
						<uni-easyinput type="text" v-model="formData.time1_2" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show1_2" v-model="formData.time1_2" mode="time" @confirm="confirm2(1)"
							@cancel="cancel2(1)"></u-datetime-picker>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">灯箱时间:</text>
				</u-col>
				<u-col span="4">
					<view @click="click3(2)">
						<uni-easyinput type="text" v-model="formData.time2_1" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show2_1" v-model="formData.time2_1" mode="time" @confirm="confirm1(2)"
							@cancel="cancel1(2)"></u-datetime-picker>
					</view>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<view @click="click4(2)">
						<uni-easyinput type="text" v-model="formData.time2_2" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show2_2" v-model="formData.time2_2" mode="time" @confirm="confirm2(2)"
							@cancel="cancel2(2)"></u-datetime-picker>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">LCD时间:</text>
				</u-col>
				<u-col span="4">
					<view @click="click3(3)">
						<uni-easyinput type="text" v-model="formData.time3_1" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show3_1" v-model="formData.time3_1" mode="time" @confirm="confirm1(3)"
							@cancel="cancel1(3)"></u-datetime-picker>
					</view>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<view @click="click4(3)">
						<uni-easyinput type="text" v-model="formData.time3_2" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show3_2" v-model="formData.time3_2" mode="time" @confirm="confirm2(3)"
							@cancel="cancel2(3)"></u-datetime-picker>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="cc">
			<u-row justify="space-between" gutter="20">
				<u-col span="3">
					<text class="title">LED时间:</text>
				</u-col>
				<u-col span="4">
					<view @click="click3(4)">
						<uni-easyinput type="text" v-model="formData.time4_1" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show4_1" v-model="formData.time4_1" mode="time" @confirm="confirm1(4)"
							@cancel="cancel1(4)"></u-datetime-picker>
					</view>
				</u-col>
				<u-col span="0.5">
					<text class="title">--</text>
				</u-col>
				<u-col span="4">
					<view @click="click4(4)">
						<uni-easyinput type="text" v-model="formData.time4_2" suffixIcon="calendar" disabled />
					</view>
					<view>
						<u-datetime-picker :show="show4_2" v-model="formData.time4_2" mode="time" @confirm="confirm2(4)"
							@cancel="cancel2(4)"></u-datetime-picker>
					</view>
				</u-col>
			</u-row>
		</view>
		<u-button v-show="show" class="btn" @click="submit" type="primary" text="提交" />
	</view>
</template>

<script>
	import {
		getControllerSettingInfo
	} from '@/api/common.js';
	import {
		updateControllerSettingInfo
	} from '@/api/common.js';
	export default {
		data() {
			return {
				info: {},
				formData: {
					temp2_1:35,
					temp2_2:30,
					temp1_1:35,
					temp1_2:30,
					time1_1:'5:30',
					time1_2:'20:50',
					time2_1:'5:30',
					time2_2:'20:50',
					time3_1:'5:30',
					time3_2:'20:50',
					time4_1:'5:30',
					time4_2:'20:50',
				},
				order: {},
				show: false,
				id: '',
				value: 0,
				show1_1: false,
				show1_2: false,
				show2_1: false,
				show2_2: false,
				show3_1: false,
				show3_2: false,
				show4_1: false,
				show4_2: false,
			}
		},
		onLoad: function(option) {
			// console.log("onLoad:" + option.id)
			uni.getStorage({
				key: 'order',
				success: (e) => {
					this.order = e.data
				}
			})
			this.info = JSON.parse(option.info)
			this.id = this.info.id
			// this.id = option.id
			this.show = option.show
			this.getControllerSettingInfo()
		},
		methods: {
			// click1(e) {
			// 	console.log('1111111111111:' + e)
			// },

			click3(e) {
				console.log('222:' + e)
				if (e == 1) {
					this.show1_1 = true
				} else if (e == 2) {
					this.show2_1 = true
				} else if (e == 3) {
					this.show3_1 = true
				} else if (e == 4) {
					this.show4_1 = true
				}
			},
			cancel1(e) {
				console.log('333:' + e)
				if (e == 1) {
					this.show1_1 = false
				} else if (e == 2) {
					this.show2_1 = false
				} else if (e == 3) {
					this.show3_1 = false
				} else if (e == 4) {
					this.show4_1 = false
				}
			},
			confirm1(e) {
				console.log(e)
				if (e == 1) {
					this.show1_1 = false
				} else if (e == 2) {
					this.show2_1 = false
				} else if (e == 3) {
					this.show3_1 = false
				} else if (e == 4) {
					this.show4_1 = false
				}
			},
			click4(e) {
				if (e == 1) {
					this.show1_2 = true
				} else if (e == 2) {
					this.show2_2 = true
				} else if (e == 3) {
					this.show3_2 = true
				} else if (e == 4) {
					this.show4_2 = true
				}
			},
			cancel2(e) {
				if (e == 1) {
					this.show1_2 = false
				} else if (e == 2) {
					this.show2_2 = false
				} else if (e == 3) {
					this.show3_2 = false
				} else if (e == 4) {
					this.show4_2 = false
				}
			},
			confirm2(e) {
				if (e == 1) {
					this.show1_2 = false
				} else if (e == 2) {
					this.show2_2 = false
				} else if (e == 3) {
					this.show3_2 = false
				} else if (e == 4) {
					this.show4_2 = false
				}
			},

			getControllerSettingInfo() {
				getControllerSettingInfo({
					sid: this.id,
				}).then(res => {
					if (res.farm != null && res.farm.indexOf("-") !== -1) {
						this.formData.time1_1 = res.farm.split('-')[0]
						this.formData.time1_2 = res.farm.split('-')[1]
					}
					if (res.flight != null && res.flight.indexOf("-") !== -1) {
						this.formData.time2_1 = res.flight.split('-')[0]
						this.formData.time2_2 = res.flight.split('-')[1]
					}
					if (res.flcd != null && res.flcd.indexOf("-") !== -1) {
						this.formData.time3_1 = res.flcd.split('-')[0]
						this.formData.time3_2 = res.flcd.split('-')[1]
					}
					if (res.fled != null && res.fled.indexOf("-") !== -1) {
						this.formData.time4_1 = res.fled.split('-')[0]
						this.formData.time4_2 = res.fled.split('-')[1]
					}
					if (res.ftemp1 != null && res.ftemp1.indexOf("-") !== -1) {
						this.formData.temp1_1 = res.ftemp1.split('-')[0]
						this.formData.temp1_2 = res.ftemp1.split('-')[1]
					}
					if (res.ftemp2 != null && res.ftemp2.indexOf("-") !== -1) {
						this.formData.temp2_1 = res.ftemp2.split('-')[0]
						this.formData.temp2_2 = res.ftemp2.split('-')[1]
					}
				}).catch(err => {
					console.log(err);
					uni.showToast({
						title: err,
						icon: 'none'
					});
				})
			},
			submit() {
				// 1: arm开启时间-arm断电时间,2:灯箱的开启时间-等闲的断电时间,3:屏前风扇起转温度-屏前风扇停转温度 
				//  4: 箱体风扇起转温度-箱体风扇停转温度,5:lcd屏开启时间-lcd屏断电时间 6:led屏开启时间-led屏断电时间
				console.log(JSON.stringify(this.formData))
				updateControllerSettingInfo({
					infos: [this.formData.time1_1 + '-' + this.formData.time1_2,
						this.formData.time2_1 + '-' + this.formData.time2_2,
						this.formData.time3_1 + '-' + this.formData.time3_2,
						this.formData.time4_1 + '-' + this.formData.time4_2,
						this.formData.temp1_1 + '-' + this.formData.temp1_2,
						this.formData.temp2_1 + '-' + this.formData.temp2_2,
					],
					ids: [this.id]
				}).then(res => {
					console.log('查詢結果：' + JSON.stringify(res));
					uni.showToast({
						title: "修改成功",
						icon: 'none'
					});
					setTimeout(() => {
						uni.navigateBack();
					}, 500)
				}).catch(err => {
					console.log(err);
					uni.showToast({
						title: err,
						icon: 'none'
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		margin-top: 40rpx;
		width: 710rpx;
		margin-left: 16rpx;
		margin-right: 16rpx;
	}

	.title {
		height: 50rpx;
		position: absolute;
		transform: translate(0, -50%);
	}

	.cc {
		margin-top: 32rpx;
		height: 100rpx;		
		width: 710rpx;
	}

	.name2 {
		height: 120rpx;
		width: 84vw;
		@include flex();
		margin-bottom: 4vh;

		.name2_1 {
			color: $font-color;
			font-size: 40rpx;
			width: 100vw;
			text-align: center;
		}
	}
</style>